﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.Windsor;
using Castle.Windsor.Installer;
using Castle.MicroKernel.Registration;
using System.Collections;

namespace RA.Infrastructure
{
    public class IoC
    {
        public static readonly IoC Instance = new IoC();

        private IWindsorContainer _container;

        static IoC()
        {
            Instance._container = new WindsorContainer();
        }

        public void RegisterType<TService, TType>()
            where TType : TService
            where TService : class
        {
            _container.Register(Component.For<TService>().ImplementedBy<TType>().LifestyleTransient());
        }

        public void RegisterInstance<TService, TType>()
            where TType : TService
            where TService : class
        {
            _container.Register(Component.For<TService>().ImplementedBy<TType>().LifestyleSingleton());
        }

        public T Resolve<T>()
        {
            return _container.Resolve<T>();
        }

        public object Resolve(Type type)
        {
            return _container.Resolve(type);
        }

        public T Resolve<T>(IDictionary dict)
        {
            return _container.Resolve<T>(dict);
        }
    }
}
